import pymysql


class Connect_MySQL:
    def __init__(self):
        self.result = None
        self.formatted_result = []   # 创建数组把数据存储为键值对形式
        self.con = pymysql.connect(host="localhost", user="root", password="", port=3306, db="usermessage")
        self.cursor = self.con.cursor()

    def select(self):
        self.cursor.execute("select * from users;")   # 执行mysql语句
        self.result = self.cursor.fetchall()    # 查询所有结果并保存
        self.con.commit()

    def format_sql_data(self):
        for row in self.result:    # 遍历数据库中每一行数据
            self.formatted_result.append({
                'username': row[0],
                'password': row[1],
                'remember_pwd': row[2],
                'login_status': row[3]
            })


if __name__ == "__main__":
    class_mysql = Connect_MySQL()
    class_mysql.select()
   